package cn.kgc.crowdfundingadmin03.controller;

import cn.kgc.crowdfundingadmin03.common.CrowdFundingConstant;
import cn.kgc.crowdfundingadmin03.common.ResultEntity;
import cn.kgc.crowdfundingadmin03.pojo.Admin;
import cn.kgc.crowdfundingadmin03.pojo.Message;
import cn.kgc.crowdfundingadmin03.pojo.Role;
import cn.kgc.crowdfundingadmin03.service.MessageService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class MessageController {

    @Resource
    MessageService messageService;
    @ResponseBody
    @RequestMapping("/message/search/by/keyword")
    public ResultEntity<PageInfo<Message>> search(
            @RequestParam(value="pageNum", defaultValue="1",required = false) Integer pageNum,
            @RequestParam(value="pageSize", defaultValue="5",required = false) Integer pageSize,
            @RequestParam(value="keyword", defaultValue="",required = false) String keyword
    ) {
        //1.查询得到 pageInfo对象
        PageInfo<Message> pageInfo = messageService.queryForKeywordWithPage(pageNum, pageSize, keyword);
        //2.封装结果对象返回
        return ResultEntity.successWithoutData(pageInfo);
    }

    //根据id查询 删除ajax的数据查询
    @ResponseBody
    @RequestMapping("/message/get/list/by/id/list")
    public ResultEntity<List<Message>> getRoleListByIdList(@RequestBody List<Integer> roleIdList) {
        List<Message> roleListByIdList = messageService.getRoleListByIdList(roleIdList);
        return ResultEntity.successWithoutData(roleListByIdList);
    }


    @ResponseBody
    @RequestMapping("/message/update/role")
    public ResultEntity<String> updateRole(Message role) {
        messageService.updateRole(role);
        return ResultEntity.successWithoutData();
    }



}
